// src/directives/sticky.js
export const sticky = {
    mounted(el, binding) {
      const offset = binding.value?.offset || 0;
      const onScroll = () => {
        const scrollPosition = window.scrollY || window.pageYOffset;
        const shouldStick = scrollPosition > el.offsetTop + offset;
        
        if (shouldStick) {
          el.classList.add('is-sticky');
          el.style.width = `${el.offsetWidth}px`;
        } else {
          el.classList.remove('is-sticky');
          el.style.width = '';
        }
      };
      
      el._onScroll = onScroll;
      window.addEventListener('scroll', onScroll);
    },
    unmounted(el) {
      window.removeEventListener('scroll', el._onScroll);
    }
  };